import {depositPay} from "@/api/order";
export default {
    methods: {
        depositLeasePay(id) {
            uni.showLoading({
                title: '加载中...'
            })
            let that = this
            depositPay(id, {
                num: 1,
                paytype: 'alipay',
                from: 'ali_routine',
                quitUrl: '/pages/goods/lease_order_details/index'
            }).then(res => {
            if (res.status === 200) {
                let status = res.data.status,
                    orderId = res.data.result.order_id || '',
                    tradeNo = res.data.result.trade_no || '',
                    jsConfig = res.data.result.jsConfig;
                switch (status) {
                    case 'ALIPAY_PAY':
                        console.log('ALIPAY_PAY_MP-ALIPAY');
                        if(tradeNo){
                            my.tradePay({
                                tradeNO: tradeNo,
                                success: (e) => {
                                    if (e.resultCode == 9000) {
                                        that.$util.Tips({title: '支付成功'})
                                        that.depositPaySuccess()
                                    }
                                },
                                fail: (e) => {
                                    console.log('支付失败', e)
                                    that.$util.Tips({title: '支付失败'})
                                },
                                complete: (e) => {

                                },
                            });
                        }else{
                            // 老订单支付：兼容旧订单
                            uni.requestPayment({
                                provider: 'alipay',
                                orderInfo: jsConfig.tradeNo,
                                success: (e) => {
                                    console.log(e)
                                    if (e.resultCode == "6001") {

                                    } else {
                                        that.$util.Tips({title: '押金支付成功'})
                                        that.depositPaySuccess()
                                    }
                                },
                                fail: (e) => {
                                    console.log('ALIPAY_PAY_fail', e);
                                    that.$util.Tips({title: '押金支付失败'})
                                },
                                complete: () => {

                                },
                            });
                        }
                        break;
                }
            }
        }).finally(() => {
            uni.hideLoading()
            })
    }
    }
}

